#include "config.h"
#include "isr.h"

#define SYSTICK
#define EXTI
#define TIMER

#ifdef SYSTICK
// SysTick interrupt handler - called every 1 ms (configured by SysConfig)
void SysTick_Handler(void)
{
	msTicks++;
}
#endif

#ifdef EXTI
/*
 * Group1 IRQ handler handles GPIOA interrupts among others.
 * SysConfig enabled PA7 (GPIOA pin 7) as falling edge interrupt.
 */
void GROUP1_IRQHandler(void)
{
	/* Check if GPIOA PA7 triggered (enabled interrupt status) */
	if (DL_GPIO_getEnabledInterruptStatus(ENCODER_PORT, ENCODER_EC11_KEY_PIN) & ENCODER_EC11_KEY_PIN)
	{
		/* Clear the interrupt flag for PA7 */
		DL_GPIO_clearInterruptStatus(ENCODER_PORT, ENCODER_EC11_KEY_PIN);
		/* Set a flag for the main loop or other tasks to process */
		encoderEvent = 1;
	}

	/* If other Group1 sources exist, optionally check/clear them here.
	 * DL_Interrupt_getStatusGroup and DL_Interrupt_clearGroup can be used
	 * for group-level handling if needed.
	 */
	
}

#endif

#ifdef TIMER

void TIM0_INST_IRQHandler(void)
{
	/* Check if TIM0 update interrupt is pending */
	if (DL_Timer_getPendingInterrupt(TIM0_INST) & DL_TIMERA_INTERRUPT_LOAD_EVENT)
	{
		/* Clear the interrupt flag */
		DL_Timer_clearInterruptStatus(TIM0_INST, DL_TIMERA_INTERRUPT_LOAD_EVENT);
		
		/* Handle the timer event (e.g., toggle an LED, update a counter) */
		timerEvent = 1;
	}
}

#endif